package com.trendit.print.sdk.example;

import com.alibaba.fastjson.JSON;
import com.trendit.print.sdk.DefaultApiClient;
import com.trendit.print.sdk.models.printer.AddPrinterRequest;
import com.trendit.print.sdk.models.soundbox.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * 云喇叭Example
 */
public class SoundBoxExample {

    private static String appId = "1663177933839273984";
    private static String appKey = "c0190e337aae4da69d737b7151295576";
    private static String endpoint = "http://opensvr-gateway-test.juheba.top:8888";

    private static String deviceNo = "P35110000784";


    public static void main(String[] args) throws InterruptedException {
        SoundBoxExample soundBoxExample = new SoundBoxExample();
//        soundBoxExample.unbindSoundBox();
//        soundBoxExample.bindSoundBox();
        for (int i = 0; i < 5000; i++) {
            soundBoxExample.doPlayVoice();
            Thread.sleep(100);
        }
        soundBoxExample.getPlayVoiceResult();
    }

    void bindSoundBox() {
        AddSoundBoxRequest.Model model = new AddSoundBoxRequest.Model();
        model.setLang(16);
        model.setName(deviceNo);
        model.setSn(deviceNo);

        List<AddSoundBoxRequest.Model> models = new ArrayList<>();
        models.add(model);

        AddSoundBoxRequest addSoundBoxRequest = new AddSoundBoxRequest(models);

        DefaultApiClient defaultApiClient = new DefaultApiClient(appId, appKey, endpoint);
        AddSoundBoxResponse addSoundBoxResponse = defaultApiClient.execute(addSoundBoxRequest);
        System.out.println(JSON.toJSONString(addSoundBoxResponse));
    }

    void unbindSoundBox() {
        List<String> deviceNos = new ArrayList<>();
        deviceNos.add(deviceNo);

        DeleteSoundBoxRequest deleteSoundBoxRequest = new DeleteSoundBoxRequest(deviceNos);

        DefaultApiClient defaultApiClient = new DefaultApiClient(appId, appKey, endpoint);
        DeleteSoundBoxResponse deleteSoundBoxResponse = defaultApiClient.execute(deleteSoundBoxRequest);
        System.out.println(JSON.toJSONString(deleteSoundBoxResponse));

    }

    void doPlayVoice() {

        DoPlayRequest.Model.VoiceText voiceText1 = new DoPlayRequest.Model.VoiceText();
        voiceText1.setType(1);
        voiceText1.setValue("微信收款");

        DoPlayRequest.Model.VoiceText voiceText2 = new DoPlayRequest.Model.VoiceText();
        voiceText2.setType(2);
        voiceText2.setValue("8");

        DoPlayRequest.Model.VoiceText voiceText3 = new DoPlayRequest.Model.VoiceText();
        voiceText3.setType(1);
        voiceText3.setValue("圆");

        List<DoPlayRequest.Model.VoiceText> voiceTexts = new ArrayList<>();
        voiceTexts.add(voiceText1);
        voiceTexts.add(voiceText2);
        voiceTexts.add(voiceText3);

        DoPlayRequest.Model model = new DoPlayRequest.Model();
        model.setOrderId(UUID.randomUUID().toString());
        model.setSn(deviceNo);
        model.setExpiredSec(100);
        model.setContentList(voiceTexts);

        DoPlayRequest doPlayRequest = new DoPlayRequest(model);
        DefaultApiClient defaultApiClient = new DefaultApiClient(appId, appKey, endpoint);
        DoPlayResponse doPlayResponse = defaultApiClient.execute(doPlayRequest);
        System.out.println(JSON.toJSONString(doPlayResponse));

    }

    void getPlayVoiceResult() {
        GetPlayResultRequest.Model model = new GetPlayResultRequest.Model();
        model.setPlayId(1697154847225171968L);
        model.setSn(deviceNo);

        GetPlayResultRequest getPlayResultRequest = new GetPlayResultRequest(model);

        DefaultApiClient defaultApiClient = new DefaultApiClient(appId, appKey, endpoint);
        GetPlayResultResponse getPlayResultResponse = defaultApiClient.execute(getPlayResultRequest);
        System.out.println(JSON.toJSONString(getPlayResultResponse));
    }

}
